<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>周末</title>
	</head>

	<body>
		<h4><a href="marquee.html">下一题</a></h4>	
		<h4><a href="caroursel.html">轮播</a></h4>	
		<h4><a href="http://sum-l.gitee.io/sum-l-imitate-meidi/">主页</a></h4>
		<h4><a href="http://sum-l.gitee.io/sum-l-imitate-meidi/login.html">登录
		</a></h4>
		<script type="text/javascript">
			//			1. 有段文字text = "and in it he says Any damn fool could", 不改变原text的前提下， 提取第一段话a = "Any damn fool could", 第二段话b = "and", 第三段话c = "could", 注意， slice() 可以接受负数, string.slice().
			var slice_str = "text = and in it he says Any damn fool could",
				a = "第一段话",
				b = "第二段话",
				c = "第三段话";
			document.write(a + slice_str.slice(-19));
			document.write("<br />")
			document.write(b + slice_str.slice(7, 10));
			document.write("<br />")
			document.write(c + slice_str.slice(-6));
			document.write("<br />")
			//			2. 字符串digite = "0123456789", 把前5个字符分割出来， 返回个单字符的数组, 注意， 返回数组里面的数字是字符串类型, string.split()
			var digite = "0123456789";
			document.write(digite.split("", 5));
			document.write("<br />")
			//3.已知有字符串foo=”get-element-by-id”,写一个function将其转化成驼峰表示法”getElementById”.

			var foo = 'get-element-by-id';
			String.prototype.transform = function() {
				var arr = this.split('-');
				for(var i = 1; i < arr.length; i++) {
					arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].substring(1);
				}
				return arr.join('');
			}
			document.write(foo.transform());
			document.write("<br />")

			//面向对象加普通string方法 
			//4.定义一个函数,将"今天是什么鬼天气，这么热，明天要去游泳！"里面的有"天"的下标输出(用indexof())
			//var wtf
			//5.定义一个函数,将"今天是什么鬼天气，这么热，明天要去游泳！"里面的有"天"替换成"日"(用replace())str.replace(/word/g,"Excel")
			var wtf_1 = "今天是什么鬼天气，这么热，明天要去游泳！";
			var wtf_2 = wtf_1.replace(/天/g, "日");
			document.write(wtf_2);
			document.write("<br />")
			//6.移除数组 arr 中的2。不要直接修改数组 arr，结果返回新的数组
			var arr = [1, 2, 3, 4, 2];
			for(var i = 1; i <= arr.length; i++) {
				if(arr[i] == 2) {
					arr.splice(i, 1);
					i--;
				}
			}
			document.write(arr)
			document.write("<br />")
			//7.定义一个函数,能在数组 arr[1, 2, 3, 4, 2] 的 "2"后面添加元素 "Melon"。不要直接修改数组 arr，结果返回新的数组
			var arr1 = [1, 2, 3, 4, 2];
			for(var i = 1; i <= arr1.length; i++) {
				if(arr1[i] == 2) {
					new_arr1 = arr1;
					new_arr1.push("sum");
					i++;
				}
			}
			document.write(new_arr1);
			document.write("<br />")
			//8.统计数组 arr[1, 2, 3, 4, 2] 中2出现的次数
			var arr2 = [1, 2, 3, 4, 2],
				sum = 0;
			for(var i = 1; i <= arr2.length; i++) {
				if(arr2[i] == 2) {
					sum++;

				}
			}
			document.write(sum);
			document.write("<br />")
			//9.找出数组 arr[1, 2, 3, "melon", 4, "melon", 2, 4, "melon"] 中重复出现过的元素,并用数组将重复元素装起来输出
			var arr4 = [1, 2, 3, "melon", 4, "melon", 2, 4, "melon"];
			var new_arr2 = new Array();
			for(var i = 0; i < arr4.length; i++) {
				for(var j = 1 + i; j < arr4.length; j++) {
					if(arr4[i] == arr4[j]) {
						new_arr2.push(arr4[i]);
					}
					var p = 0;
					for(var n = 0; n < new_arr2.length; n++) {
						if(new_arr2[n] == arr4[i]) {
							p++;
						}
						if(p > 1) {
							new_arr2.splice(n, 1);
						}
					}
				}
			};
			alert(new_arr2);

			//10.在arr里面输出年龄小于17的对象
			//			var arr = [
			//				{ name: "111", sex: "boy", age: 18 },
			//				{ name: "222", sex: "girl", age: 17 },
			//				{ name: "333", sex: "boy", age: 16 },
			//				{ name: "444", sex: "girl", age: 15 },
			//				{ name: "555", sex: "boy", age: 20 }
			//			]
			var arr3 = [{
					name: "111",
					sex: "boy",
					age: 18
				},
				{
					name: "222",
					sex: "girl",
					age: 17
				},
				{
					name: "333",
					sex: "boy",
					age: 16
				},
				{
					name: "444",
					sex: "girl",
					age: 15
				},
				{
					name: "555",
					sex: "boy",
					age: 20
				}
			]
			for(var i = 0; i < arr3.length; i++) {
				if(arr3[i].age < 17) {
					console.log(arr3[i]);
				}
			}
		</script>
	</body>

</html>